package org.labj;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ExecutorServiceExample {
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(10);
        // submit all your tasks to the executor service
        for (int i = 0; i < 12; i++) {
            es.submit(() -> {
                System.out.println("go to hell");
            });
        }

        // initiate an orderly shutdown of the executor service
        es.shutdown();
        try {
            // wait for all tasks to complete or until the timeout occurs
            boolean terminated = es.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
            if (terminated) {
                System.out.println("All tasks have completed successfully");
            } else {
                System.out.println("Timeout occurred before all tasks could complete");
            }
        } catch (InterruptedException e) {
            System.out.println("Execution was interrupted before all tasks could complete");
        }
    }
}